﻿using System;

namespace Luna.Core.Extensions
{
    public static class CommonExtension
    {
        public static bool IsNullOrEmpty(this string str)
        {
            return String.IsNullOrEmpty(str);
        }

        public static bool IsNotNullOrEmpty(this string str)
        {
            return !String.IsNullOrEmpty(str);
        }

        public static bool IsEqual(this string left, string right)
        {
            return String.CompareOrdinal(left, right) == 0;
        }

        public static bool IsNull(this object obj)
        {
            return obj == null;
        }

        public static bool IsNotNull(this object obj)
        {
            return !obj.IsNull();
        }

        public static T As<T>(this object obj)
        {
            return obj is T ? (T)obj : default(T);
        }

        public static T Action<T>(this T target, Action<T> action)
        {
            action(target);
            return target;
        }

    }
}
